﻿using System;
using ComputationalCore.Helper;
using ComputationalCore.Interface.RandomGenerator;

namespace ComputationalCore.Impl.RandomGenerator
{
    public class PoissonRandomGenerator : IRandomGenerator
    {
        public double Lambda { get; set; }

        public PoissonRandomGenerator()
        {
            Lambda = 1;
        }

        public PoissonRandomGenerator(double lambda)
        {
            Lambda = lambda;
        }

        public double GetNext(double prev)
        {
            return GetNext() + prev;
        }

        public double GetNext()
        {
            var next = -1 / Lambda * Math.Log(RandomHelper.NextDouble());

            return next;
        }
    }
}
